package com.vcit.student.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vcit.common.core.domain.entity.TStudent;
import com.vcit.common.utils.poi.ExcelUtil;
import com.vcit.system.domain.student.StudentDTO;
import com.vcit.system.domain.vo.StudentListVo;
import com.vcit.system.service.student.ITStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vcit.common.annotation.Log;
import com.vcit.common.core.controller.BaseController;
import com.vcit.common.core.domain.AjaxResult;
import com.vcit.common.enums.BusinessType;
import com.vcit.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
import com.vcit.common.utils.SecurityUtils;

/**
 * 学生Controller
 * 
 * @author dff
 * @date 2025-01-09
 */
@Api("学生信息管理")
@RestController
@RequestMapping("/system/student")
public class TStudentController extends BaseController
{
    @Autowired
    private ITStudentService tStudentService;


    /**
     * 查询学生详细信息 列表
     */
    @ApiOperation("获取学生详细信息系部，专业名称 ，班级名称，列表")
    @PreAuthorize("@ss.hasPermi('studentMan:list')")
    @GetMapping("/stuAllInfo")
    public TableDataInfo stuAllInfo(StudentListVo studentListVo)
    {
        startPage();
        List<StudentListVo> list = tStudentService.selectStudentAllInfoList(studentListVo);
        return getDataTable(list);
    }

    /**
     * 查询学生列表
     */
    @ApiOperation("获取学生详细信息列表")
    @PreAuthorize("@ss.hasPermi('studentMan:list')")
    @GetMapping("/list")
    public TableDataInfo list(TStudent tStudent)
    {
        startPage();
        List<TStudent> list = tStudentService.selectTStudentList(tStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生列表
     */
    @ApiOperation("导出学生详细信息列表")
    @PreAuthorize("@ss.hasPermi('system:student:export')")
    @Log(title = "学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,StudentListVo studentListVo)
    {
        List<StudentListVo> list = tStudentService.selectStudentAllInfoList(studentListVo);
        ExcelUtil<StudentListVo> util = new ExcelUtil<StudentListVo>(StudentListVo.class);
        util.exportExcel(response, list, "学生数据");
    }

    /**
     * 获取学生详细信息
     */
    @ApiOperation("获取学生详细信息")
    @PreAuthorize("@ss.hasPermi('system:student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tStudentService.selectTStudentById(id));
    }

    /**
     * 获取学生详细信息
     */
    @ApiOperation("获取学生详细包含班级专业辅导员信息")
    @PreAuthorize("@ss.hasPermi('system:student:query')")
    @GetMapping(value = "/allInfoById/{id}")
    public AjaxResult getStuAllInfoById(@PathVariable("id") Long id)
    {
        return success(tStudentService.selectStudentVoById(id));
    }

    /**
     * 新增学生
     */
    @ApiOperation("新增学生信息")
    @PreAuthorize("@ss.hasPermi('system:student:add')")
    @Log(title = "学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentDTO studentDTO)
    {
        return toAjax(tStudentService.insertTStudent(studentDTO));
    }

    /**
     * 修改学生
     */
    @ApiOperation("修改学生信息")
    @PreAuthorize("@ss.hasPermi('system:student:edit')")
    @Log(title = "学生", businessType = BusinessType.UPDATE)
    @PutMapping("/edit/sut")
    public AjaxResult edit(@RequestBody StudentDTO studentDTO)
    {
        return toAjax(tStudentService.updateTStudent(studentDTO));
    }
    /**
     * 删除学生
     */
    @ApiOperation("删除学生信息")
    @PreAuthorize("@ss.hasPermi('system:student:remove')")
    @Log(title = "学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tStudentService.deleteTStudentByIds(ids));
    }

    /**
     * 导入学生数据
     */
    @ApiOperation("导入学生数据")
    @PreAuthorize("@ss.hasPermi('system:student:import')")
    @Log(title = "学生管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<StudentListVo> util = new ExcelUtil<StudentListVo>(StudentListVo.class);
        List<StudentListVo> studentList = util.importExcel(file.getInputStream());
        String operName = SecurityUtils.getUsername();
        String message = tStudentService.importStudent(studentList, updateSupport, operName);
        return success(message);
    }

    /**
     * 下载导入模板
     */
    @ApiOperation("下载导入模板")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<StudentListVo> util = new ExcelUtil<StudentListVo>(StudentListVo.class);
        util.importTemplateExcel(response, "学生数据");
    }
}
